package com.ruoyi.project.system.house.orientation.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.house.orientation.domain.HouseOrientation;
import com.ruoyi.project.system.house.orientation.service.IHouseOrientationService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 房源朝向Controller
 * 
 * @author f_baisi
 * @date 2020-08-27
 */
@Controller
@RequestMapping("/system/house/orientation")
public class HouseOrientationController extends BaseController
{
    private String prefix = "system/house/orientation";

    @Autowired
    private IHouseOrientationService houseOrientationService;

    @RequiresPermissions("system/house:orientation:view")
    @GetMapping()
    public String orientation()
    {
        return prefix + "/orientation";
    }

    /**
     * 查询房源朝向列表
     */
    @RequiresPermissions("system/house:orientation:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(HouseOrientation houseOrientation)
    {
        startPage();
        List<HouseOrientation> list = houseOrientationService.selectHouseOrientationList(houseOrientation);
        return getDataTable(list);
    }

    /**
     * 导出房源朝向列表
     */
    @RequiresPermissions("system/house:orientation:export")
    @Log(title = "房源朝向", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(HouseOrientation houseOrientation)
    {
        List<HouseOrientation> list = houseOrientationService.selectHouseOrientationList(houseOrientation);
        ExcelUtil<HouseOrientation> util = new ExcelUtil<HouseOrientation>(HouseOrientation.class);
        return util.exportExcel(list, "orientation");
    }

    /**
     * 新增房源朝向
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存房源朝向
     */
    @RequiresPermissions("system/house:orientation:add")
    @Log(title = "房源朝向", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(HouseOrientation houseOrientation)
    {
        return toAjax(houseOrientationService.insertHouseOrientation(houseOrientation));
    }

    /**
     * 修改房源朝向
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        HouseOrientation houseOrientation = houseOrientationService.selectHouseOrientationById(id);
        mmap.put("houseOrientation", houseOrientation);
        return prefix + "/edit";
    }

    /**
     * 修改保存房源朝向
     */
    @RequiresPermissions("system/house:orientation:edit")
    @Log(title = "房源朝向", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(HouseOrientation houseOrientation)
    {
        return toAjax(houseOrientationService.updateHouseOrientation(houseOrientation));
    }

    /**
     * 删除房源朝向
     */
    @RequiresPermissions("system/house:orientation:remove")
    @Log(title = "房源朝向", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(houseOrientationService.deleteHouseOrientationByIds(ids));
    }
}
